const { exec } = require('../db/mysql')

// 查询列表数据
const getList = async (name, remark) => {
    let sql = `select * from phones where 1=1 `
    if (name) {
        sql += `and name like '%${name}%' `
    }
    if (remark) {
        sql += `and remark like '%${remark}%' `
    }

    sql += `order by createtime desc;`
    console.log(sql)
    return await exec(sql)
}

const getPhone = async (tel) => {
    const sql = `select * from phones where tel=${tel}`
    return await exec(sql)


}

// 新增
const addPhone = async (name, tel, remark = "") => {
    // if (tel) {
    //     const sql = `select * from phones where tel=${tel}`
    //     let aac = await exec(sql)
    //     console.log(aac)
    //     return;
    // }

    const sql = `INSERT INTO phones (name, tel, remark) VALUES ('${name}', '${tel}', '${remark}')`

    // // let sql = `select * from phones where 1=1 `
    // if (name) {
    //     sql += `and name='${name}' `
    // }
    // if (content) {
    //     sql += `and content like '%${content}%' `
    // }

    // sql += `order by createtime desc;`
    console.log(sql)
    return await exec(sql)
}
module.exports = {
    getList,
    addPhone,
    getPhone
}